package com.gravata.enigma.repositorio.impl;

import java.sql.SQLException;

import android.content.Context;

import com.gravata.enigma.model.Polarization;
import com.gravata.enigma.model.Profile;
import com.gravata.enigma.model.Satelite;
import com.gravata.enigma.model.Transponder;
import com.gravata.enigma.repositorio.RepositorioGenerico;
import com.gravata.enigma.repositorio.RepositorioTransponder;
import com.j256.ormlite.stmt.QueryBuilder;

public class RepositorioTransponderImpl extends RepositorioGenerico<Transponder>
		implements RepositorioTransponder {

	public RepositorioTransponderImpl(Context context) throws SQLException {
		super(context);
	}

	@Override
	public Transponder getTransponder(Profile profile,int position,int frequencia, int symbol_rate, int pol) {
		try {

			QueryBuilder<Satelite, ?> qSat= getDao(Satelite.class).queryBuilder();
			qSat.where().eq("profile_id", profile).and().eq("position", position);

			return database.queryBuilder().join(qSat).where().eq("frequency", frequencia).and()
					.eq("symbolRate", symbol_rate).and().eq("polarization", Polarization.values()[pol]).queryForFirst();


		} catch (SQLException e) {
			e.printStackTrace();
		}
		return null;
	}

}